<template>
  <div>
    <tableComponents :isHavePagination="false" :isShow="false" :isHaveExport="false" @toAdd="checkBd(true)">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="list" v-loading="loading" stripe header-row-class-name="head_color" tooltip-effect="dark"
            style="width: 99.9%">
          <!-- <el-table-column type="selection" class="tc" width="35"></el-table-column> -->

          <el-table-column label="标题" min-width="80">
            <template slot-scope="scope">{{ scope.row.title }}</template>
          </el-table-column>

          <el-table-column label="英文标识" min-width="80">
            <template slot-scope="scope">{{ scope.row.iden }}</template>
          </el-table-column>
          <el-table-column label="添加时间" min-width="100">
            <template slot-scope="scope">{{
              scope.row.created_time | getTimeFormat
            }}</template>
          </el-table-column>
          <el-table-column label="更新时间" min-width="100">
            <template slot-scope="scope">{{
              scope.row.update_time | getTimeFormat
            }}</template>
          </el-table-column>

          <el-table-column label="操作" align="center" min-width="120">
            <template slot-scope="scope">
              <el-button :loading="$store.state.isLoading" size="mini" type="success" @click="openDetails1(scope.row.id, scope.row.title)">查看
              </el-button>
              <el-button :loading="$store.state.isLoading" size="mini" type="primary" @click="openDetails(scope.row.id, scope.row.title)">字段管理
              </el-button>
              <el-button :loading="$store.state.isLoading" size="mini" type="warning" @click="checkBd(false, scope.row)">编辑</el-button>
              <el-button :loading="$store.state.isLoading" size="mini" @click="deleteNew(scope.$index, scope.row.id)" type="danger">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>
    
    <el-dialog :close-on-click-modal="false" title="表管理" :modal-append-to-body="false" :append-to-body="true" :visible.sync="showCharacterForm"
        class="tl size_13" width="800px">
      <characterForm v-if="showCharacterForm" @hideDio="getHideDio" :row="row" />
    </el-dialog>
  </div>
</template>
<script>
import HeadTitle from "@/components/currency/HeadTitle.vue";
import characterForm from "./characterForm";
export default {
  data () {
    return {
      list: [],
      loading: true,
      showCharacterForm: false,
      row: {}
    };
  },
  components: {
    HeadTitle,
    characterForm
  },
  methods: {
    openDetails (id) {
      // let routeData = this.$router.resolve({
      //   path: "/index/admin/characterField",
      //   query: { id: id }
      // });
      this.$store.commit("addbreadcrumbs", {
        title: "字段管理",
        url: `/index/plugin/characterField?id=${id}&page=1`
      });
      this.$router.push({
        path: "/index/plugin/characterField",
        query: { id: id, page: 1 }
      });
      // this.$store.commit("setFieldId", routeData.href.split("=")[1]);
      // window.open(routeData.href, "_blank");
    },
    openDetails1 (id, title) {
      this.$store.commit("addbreadcrumbs", {
        title: "查看详情",
        url: `/index/plugin/characterInfo?id=${id}&title=${title}`
      });
      this.$router.push({
        path: "/index/plugin/characterInfo",
        query: { id: id, title: title }
      });
      // window.open(routeData.href, "_blank");
    },
    getHideDio (bool) {
      this.showCharacterForm = false;
      if (bool) {
        this.getNewsAll();
      }
    },
    checkBd (bool, row) {
      if (bool) {
        this.row = {};
      } else {
        this.row = row;
      }
      this.showCharacterForm = true;
    },
    getOpen (val, row) {
      var params = {};
      params = row;
      params.is_open = val;
      this.updata(params);
    },
    getPay (val, row) {
      var params = {};
      params = row;
      params.is_pay = val;
      this.updata(params);
    },
    updata (row, bool) {
      var params = {};
      params = row;
      this.$api.getCharacter.characterCateSaveadd(params).then(res => {
        if (res.data.status == 1 && res.data.code == 200) {
          // if (bool) {
          this.$message.success("提交成功");
          // }
          //  this.$message.success('提交成功');
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result);
        }
      });
    },
    getNewsAll () {
      this.$api.getCharacter.getCharacterCateList().then(res => {
        console.log(res);
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    deleteNew (index, id) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          var data = { id: id };
          this.$api.getCharacter.characterCateDel(data).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              this.list.splice(index, 1);
            } else {
              this.$swal("删除失败！", res.data.result, "error");
            }
          });
        }
      });
    }
  },

  created () {
    this.getNewsAll();
  }
};
</script>

<style lang="less" scoped>
thead > tr > th {
  height: 45px;
  line-height: 45px;
}
td,
th {
  border: 1px solid #e1e3e4;
  font-size: 12px;
}
th {
  background: #f8f8f8;
  font-weight: normal;
  color: #323437;
}
td {
  height: 75px;
  color: #000;
}
.caozuo {
  padding-left: 50px;
}
.pl {
  padding-left: 15px;
}
.chkBox {
  display: block;
  margin: 0 auto;
  width: 18px;
  height: 18px;
  background: #fff;
}
.aBtn_1 {
  padding: 10px;
}
</style>
